<script>
// 递归实现斐波那契数列
function fibonacci(n){
    if(n < 2){
        return n
    }
    return fibonacci(n - 1) + fibonacci(n - 2)
}
console.log(fibonacci(5));
// 循环实现斐波那契数列
function fibonacci2(n){
    if(n < 2){
        return n 
    }
    var cache = []
    cache[0] = 0
    cache[1] = 1
    for (let i = 2; i <= n; i++){
        cache[i] = cache[i - 1] + cache[i - 2]
    }
    return cache[n]
}
console.log(fibonacci2(5));

</script>